- /* slmsetdb.cpp by K.Tsuru */
- // function ID 202 DRADIX
- #ifndef SN_H
- #include "sn.h"
- #endif
-
- /**************************************************
- SLong class
- Set a value by double including unsignd long, etc.
- ****************************************************/
- void SLong::SetDouble(double d){
- double absd = fabs(d), rdx = Radix();
- SetZero();
- if(absd < 1.0) return; // d = 0, sign = 0
- //This error check is not necessary because of SLong's protected function.
- //if( (absd >= rdx) && rdx != DRADIX) SetError(RADIX_ERR,"SL SetDouble", 202);
-
- double ulmax = (double)ULONG_MAX;
-
- if(absd < rdx){ //less than radix
- figure[0] = (fType)absd; // aHead = aTail = 0
- } else if(absd <= ulmax){
- ulong t = (ulong)absd;
- int i = 0, tf = 0; //flag to detect aTail
- //less than tree figures because ULONG_MAX < radix^3
-
- while(t){
- figure[i] = fType(t % DRADIX);
- if(figure[i] && !tf){ aTail = i; tf = 1; }
- t /= DRADIX; i++;
- }
- aHead = i-1; // i>=1 and over two figures
- } else {
- uint sz;
- int j, k;
- FigBlock r;
- int e = doubleToArray(absd, r, &sz);
- #ifndef NDEBUG
- assert(e > 0);
- // if( (e <= 0) || !r(1)){ SetSign(0); return; } // x = 0
- #endif
- k = min( (int)sz, e+1);
- figure.reserve(e-1);
- for(j = 1; j < k; j++) figure[e-j] = r(j);
- j = e -k + 1;
- while(!figure(j)) j++;
- aHead = (uint)e-1; aTail = (uint)j;
- }
- SetSign(d); //Set sign at last.
- }
slmsetdb.cpp : last modifiled at 2017/03/13 14:32:01(1,458 bytes)
created at 2017/10/07 10:26:49
The creation time of this html file is 2017/11/09 14:52:03 (Thu Nov 09 14:52:03 2017).